#!/usr/bin/env python3
# -*- encoding: utf-8 -*-
'''
@author: yuejl
@application:
@contact: lewyuejian@163.com
@file: takes.py
@time: 2021/3/24 0024 18:41
@desc:
'''

import json
from functools import wraps

from wechatapi.parser import parser_yaml_data, parser_testcase_entries


def json_converter(func):
    """将被装饰函数的返回结果转换成JSON格式"""

    @wraps(func)
    def wrapper(*args, **kwargs):
        """闭包函数"""
        result = func(*args, **kwargs)
        json_res = json.dumps(result)
        return json_res

    return wrapper


@json_converter
def my_test():
    # 创建字典类型返回值
    return dict(name="Ammy", passwd=666666, age=16)

################

def use_mapping(name):
    """根据key获取函数返回结果为字典的值"""
    def decorator(func):
        def wrapper(*args, **kwargs):
            result = func(*args, **kwargs)
            extract_res = result[name]
            return extract_res
        return wrapper
    return decorator

# 实现参数化
def testcase_parameterize(api_content):
    '''实现参数化'''

    def decorator(func):
        def wrapper(*args, **kwargs):
            for item in api_content:
                print(item)
                res = func(item, *args, **kwargs)

                return res
        return wrapper

    return decorator



# https://www.pianshen.com/article/8707201826/

if __name__ == '__main__':
    # json_res = my_test()
    # print("被装饰后返回结果：", json_res)
    # print("被装饰后返回结果数据类型：", type(json_res))
    token = "xb9xiOhqsUimwRaDjSxqdTz-qFFORAIKg0keChVSLDFbk7R_PLXZoMfuzd95akd4RxdIeU7t0BQzsqBJwQ24mgJBXEf0DsukCjvRtlyhZFxUoIHWEd52-F1ilDhV_CWW4_i3Brm-PT9QD-RfxOusBNdLnp80hUw88Ejtus1i87Cnv_2wTMIcX2YUX5ZPf2Od-iFrejODrTT2dKnS7hh1ig"
    yaml_file = r"D:\CodeBase\auto\WechatApi\wechatapi\data\testdatas\test_member.yaml"
    create_member_params = parser_yaml_data(yaml_file, 'create_member', token)
    data = parser_testcase_entries(create_member_params)


    @testcase_parameterize(data)
    def test_001(api):
        print(api)
    test_001()

